define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user.user/index',
                    add_url: '',
                    edit_url: 'user.user/edit',
                    del_url: 'user.user/del',
                    multi_url: '',
                }
            });
            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                columns: [
                    [
                        {field: 'state', checkbox: true, },
                        {field: 'id', title: 'ID'},
                        {field: 'username', title: '用户', operate:false},
                        {field: 'nickname', title: '用户昵称', operate:false},
                        {field: 'avatar', title:'用户头像', events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false},
                        {field: 'mobile', title: '手机号'},
                        {field: 'balance', title: '余额'},
                        {field: 'score', title: '健康币'},
                        {field: 'status', title: '状态',formatter:function (value) {
                                if(value == 1){
                                    return '<span class="text-success"><i class="fa fa-circle"></i> 正常</span>';
                                }else{
                                    return '<span class="text-success"><i class="fa fa-circle"></i> 下线</span>';
                                }
                            },operate:false
                        },
                        {field: 'loginip', title: 'IP'},
                        {field: 'createtime', title: '注册时间',formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), events: Controller.api.events.operate, formatter: Controller.api.formatter.operate}

                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter: {
                operate: function (value, row, index) {
                    return '<a class="btn btn-info btn-xs btn-detail">用户信息</a> '
                        + Table.api.formatter.operate(value, row, index, $("#table"));
                },
            },
            events: {
                operate: $.extend({
                    'click .btn-detail': function (e, value, row, index) {
                        Backend.api.open('user.user/detail/ids/' + row['id'], __('Detail'));
                    }
                }, Table.api.events.operate)
            }
        }
    };
    return Controller;
});